
#ifndef OGDL_SOCKET_WIN32_H__
# define OGDL_SOCKET_WIN32_H__

# include <WinSock2.h>
# pragma comment (lib, "Ws2_32.lib")

# include <ogdl/network/Net.h>
# include <ogdl/network/ISocket.h>

namespace ogdl
{

    class SocketImpl : public ISocket
    {
    private:
        static unsigned int _count;
        static void startup();
        static void cleanup();
    public:
        SocketImpl();
        SocketImpl(SocketImpl const &);
        ~SocketImpl();
        SocketImpl &operator=(SocketImpl const &);

        virtual void socket(net::SockDomain domain, net::SockType type);
        virtual void bind(std::string const & host, int port);
        virtual void listen(int backlog);
        
        virtual void accept(ISocket *client); // TCP server-side only !
        virtual void connect(std::string const &host, int port); // TCP client-size only !

        virtual void close();

        virtual void read(void *buf, size_t len, int flags) = 0;
        virtual void write(void *buf, size_t len, int flags) = 0;

        virtual std::string const & lastError() const;
    private:
        SOCKET _sock;
        net::SockDomain _domain;
        net::SockType _type;
        
        std::string _err;
        
        SOCKADDR_IN _sin;
        size_t _len;
    };

}

#endif  // OGDL_SOCKET_WIN32_H__